<?php

include_once('db_connection.php');

class add_bankdetail {

    function bankdetail_add($affiliate_id) {
        $data = $this->get_details($affiliate_id);
        
        $b_affilate_id = $affiliate_id;
        $b_payment_type = addslashes($_POST['payment_method']);
        $b_bank_name = addslashes($_POST['b_bank_name']);
        $b_bank_acc_no = addslashes($_POST['b_bank_acc_no']);
        $b_bank_branch = addslashes($_POST['b_bank_branch']);
        $b_bank_swipe_code = addslashes($_POST['b_bank_swipe_code']);
        $b_paypal_name = addslashes($_POST['b_paypal_name']);
		
        $b_address = addslashes($_POST['b_address']);
        $b_pancard = $_POST['b_pancard'];
        
        if(count($data) == 0){
          $insert_details = "INSERT into tbl_bank_detail (`b_affilate_id`, `b_payment_type`, `b_bank_name`, `b_bank_acc_no`, `b_bank_branch`, `b_bank_swipe_code`, `b_paypal_name`,`b_pancard`,b_address, `b_createdate`, `b_updateddate`)
           VALUES ('" . $b_affilate_id . "','" . $b_payment_type . "', '" . $b_bank_name . "', '" . $b_bank_acc_no . "', '" . $b_bank_branch . "', '" . $b_bank_swipe_code . "', '" . $b_paypal_name . "','".$b_pancard."','".$b_address."', '" . date('Y-m-d H:i:s') . "','" . date('Y-m-d H:i:s') . "')";
          $rows = mysql_query($insert_details) or die(mysql_error());
          $success_msg = "Bank details Has been Sucessfully Added";
        }else{
            $update_details = "UPDATE `tbl_bank_detail` SET `b_payment_type`='".$b_payment_type."',`b_bank_name`= '".$b_bank_name."',
                `b_bank_acc_no`= '".$b_bank_acc_no."',`b_bank_branch`='".$b_bank_branch."',
                    `b_bank_swipe_code`='".$b_bank_swipe_code."',`b_paypal_name`='".$b_paypal_name."',
                        b_pancard = '".$b_pancard."' ,
b_address = '".$b_address."',                        
`b_updateddate` = '".date('Y-m-d H:i:s')."' WHERE b_affilate_id = '".$b_affilate_id."'";
            $rows = mysql_query($update_details) or die(mysql_error());
            $success_msg = "Bank details Has been Sucessfully Updated";
        }
        return $success_msg;
    }

    function get_details($id) {
        $select = "SELECT * FROM tbl_bank_detail WHERE b_affilate_id='" . $id . "'";
        $query = mysql_query($select) or die(mysql_error());

        if (mysql_num_rows($query)) {
            $results = array();
            while ($row = mysql_fetch_array($query)) {
                foreach ($row as $k => $v) {
                    $result->$k = $v;
                }

                $results[] = $result;
            }
            return $results;
        }
    }

   
}

?>